<?php
if($api_authcode_human['api_authcode_human_open'] == 'open'){
    if($_SESSION['exam_smrz'] !== true){
      die("您当前未实名认证，请先进行实名认证！");
    }
  }
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选择一份试卷</title>
    <link rel='stylesheet' href='/ast/message/message.min.css'>
    <script src='/ast/message/message.min.js'></script>
</head>
<style>
    body, html {
    height: 100%;
    margin: 0;
    font-family: Arial, sans-serif;
    background: #f8f4e4;
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

#searchBox {
    padding: 10px;
    font-size: 16px;
    border: none;
    border-radius: 5px;
    outline: none;
    box-shadow: 0 0 10px rgba(255, 192, 203, 0.5); 
    background: rgba(255, 192, 203, 0.3); 
    color: #333;
}

#listContainer {
    list-style: none;
    padding: 0;
    margin-top: 20px;
    width: 300px;
    background: rgba(255, 192, 203, 0.3); 
    box-shadow: 0 0 10px rgba(255, 192, 203, 0.5); 
    border-radius: 5px;
    overflow: auto;
}

#listContainer li {
    padding: 10px;
    border-bottom: 1px solid #f8e4e4;
    cursor: pointer;
}

#listContainer li:last-child {
    border-bottom: none;
}

#listContainer li:hover {
    background-color: rgba(255, 192, 203, 0.5);
}
#addButton {
    padding: 10px 20px;
    font-size: 16px;
    border: none;
    border-radius: 5px;
    outline: none;
    cursor: pointer;
    background: rgba(255, 192, 203, 0.7);
    box-shadow: 0 0 10px rgba(255, 192, 203, 0.5);
    color: #fff;
    margin-top: 10px;
}
#addButton:hover {
    background: rgba(255, 192, 203, 0.8); 
}
#listcontainerfath{overflow:auto;height:200px; }
.hidden {
    display: none;
}
@keyframes fadeIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  .highlight{
    border: 2px solid #000; 
    box-shadow: 0 0 10px #000; 
  }
  #contextMenu {
    display: none;
    position: absolute;
    background-color: #fff;
    border: 1px solid #ccc;
    padding: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2); 
    border-radius: 5px; 
    overflow: hidden; 
    z-index: 1000; 
    font-family: 'Arial', sans-serif; 
    animation: fadeIn 0.3s ease-in-out; 
  }
  
  #contextMenu ul {
    list-style: none; 
    margin: 0;
    padding: 0;
  }
  
  #contextMenu li {
    padding: 5px 10px; 
    cursor: pointer;
    transition: background-color 0.2s; 
  }
  
  #contextMenu li:hover {
    background-color: #f0f0f0; 
  }
  
  #contextMenu li:not(:last-child) {
    border-bottom: 1px solid #eee; 
  }
</style>
<body>
<div id="contextMenu" style="display: none; position: absolute; background-color: #fff; border: 1px solid #ccc; padding: 5px;">
  <ul>
    <li onclick="deloneinexamof();">删除</li>
  </ul>
</div>
    <div class="container">
        <input type="text" id="searchBox" placeholder="搜索...">
        <button id="addButton">搜索</button>
        <div id="listcontainerfath">
        <ul id="listContainer">
           
        </ul>
        </div>
    </div>
</body>
</html>
<script>
    function deloneinexamof(){
    fetch('exam/deloneexamdone.php?param1='+nowmenushowbything2)
    .then(function (response) {
        return response.json();
    }).then(function (data) {
        if (data.status !== 200) {
            Qmsg.error('删除失败，请尝试刷新页面');
        }else{
            Qmsg.success('删除成功');
            document.querySelector(`[tystatus="${nowmenushowbything2}"]`).remove();
        }});
}
        function searchitems() {
        const searchQuery = searchBox.value.toLowerCase();
        const listItems = listContainer.querySelectorAll('.searchable');
        listItems.forEach(function(item) {
            if (item.textContent.toLowerCase().includes(searchQuery)) {
                item.classList.remove('hidden');
            } else {
                item.classList.add('hidden');
            }
        });
    }
    let nowmenushowbything2 = null;
    function hideorshowsibcon(e,id){
        nowmenushowbything2 = id;
    e.preventDefault(); 
      document.querySelector(`[tystatus="${id}"]`).classList.add('highlight');
      nowmenushowbything = document.querySelector(`[tystatus="${id}"]`);
        var x = e.clientX;
        var y = e.clientY;
        document.getElementById('contextMenu').style.display = 'block';
        document.getElementById('contextMenu').style.left = x + 'px';
        document.getElementById('contextMenu').style.top = y + 'px';
        document.addEventListener('click', function hideMenu() {
            document.getElementById('contextMenu').style.display = 'none';
            document.querySelector(`[tystatus="${id}"]`).classList.remove('highlight');
            document.removeEventListener('click', hideMenu);
    });
    e.stopPropagation();
  }
    const searchBox = document.getElementById('searchBox');
    const listContainer = document.getElementById('listContainer');

    searchBox.addEventListener('input', function() {
       searchitems();
    });
    function geturlsearch_main(){ //获取页面参数
    var queryString = window.location.search; 
    var valueAfterQuestionMark = queryString.substring(1);
    return valueAfterQuestionMark;
}

    var formData = new FormData();
    var jks = geturlsearch_main().split('|')[0];
    formData.append('param1', jks.split('=')[1]);
    fetch('exam/searchfromexam.php',{
    method: 'POST',
          body: formData
      })
      .then(function (response) {
          return response.json();
      }).then(function (data) {
        if (data.code !== 200) {
            Qmsg.error('加载失败，请尝试刷新页面');
        }else{
            var ewsult = data.result;
            ewsult.forEach(godin => {
                var ifzb = (godin.ifzb) === 0 ? '诚信者' : '作弊者';
                var ifpyy = (godin.score) !== null ? '已批阅' : '未批阅';
                const li = document.createElement('li');
                li.classList.add('searchable');
                li.textContent = godin.aname+'(IP:'+godin.ip+')'+'('+ifzb+')'+'('+ifpyy+')';
                listContainer.appendChild(li);
                li.setAttribute('zbelse', godin.ifzb);
                li.setAttribute('tystatus', godin.lisid);
                li.addEventListener('contextmenu', function(e) {
                    hideorshowsibcon(e,godin.lisid);
                });
                li.addEventListener('click', function() {
                    if(this.getAttribute('zbelse') === '1'){
                        Qmsg.error('作弊者试卷默认0分，无需查看');
                        return;
                    }
                    location.href = './?seein='+godin.lisid+'&examname='+godin.aname;
                    event.stopPropagation();
                });
            });
        }
    })

</script>